﻿using FastCodeGeneration.Entity;
using FastCodeGeneration.IService;
using Microsoft.AspNetCore.Mvc;
using FastCodeGeneration.Models;
using FastCodeGeneration.Core.Framework;

namespace FastCodeGeneration.Controllers
{
    public class ProjectController : Controller
    {

        private readonly IProjectService _projectService;

        public ProjectController(IProjectService projectService)
        {
            _projectService = projectService;
        }

        public IActionResult Index()
        {
            return View();
        }

        public IPage<Project> GetList(int pageIndex, int pageSize)
        {
            Page<Project> page = new Page<Project> { PageIndex = pageIndex, PageSize = pageSize };
            _projectService.SelectPage(page, null);
            return page;
        }

        public IActionResult AddOrEdit(int id)
        {
            var entity = _projectService.SelectById(id) ?? new Project();
            return View(entity);
        }
        public AjaxResult Save(Project entity)
        {
            bool res = _projectService.SaveProject(entity);
            return new AjaxResult { Code = 200, Message = "保存成功", Data = entity };
        }

        [HttpDelete]
        public IActionResult Delete(int id)
        {
            return View();
        }

        public AjaxResult Pull(int id)
        {
            _projectService.Pull(id);
            return new AjaxResult { Code = 200, Message = "同步成功"};
        }


    }
}
